package com.laker.autotest.page.gitee;


import com.laker.autotest.core.BasePage;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;

/**
 * <p>
 * https://playwright.dev/java/docs/pom
 * 页面对象模型，目的是为了代码维护方便。
 * 以搜索功能为例，搜索页面需要存放元素定位和控件操作行为。
 * gitee 搜索页
 * </p>
 */
public class GiteeSearchPage extends BasePage {
    private static final String URL = "https://search.gitee.com/";

    private final Locator searchInput;
    private final Locator searchBtn;

    public GiteeSearchPage(Page page) {
        super(page);
        // <input type="text" name="q" class="input" id="search-input"
        searchInput = getComponentById("search-input");
        // <button class="submit">搜索</button>
        searchBtn = getComponentByClassName("submit");
    }

    @Override
    protected String pageUrl() {
        return URL;
    }


    public GiteeRepoPage search(String kw) {
        searchInput.fill(kw);
        searchBtn.click();
        Page page1 = page.waitForPopup(() -> {
            page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("laker/EasyAutoTest")).click();
        });
        return new GiteeRepoPage(page1);
    }

}
